package ua.khpi.si.kit49.diploma.db.dto;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Class represents road quality of roads between the cities
 * 
 * @author netstalk3r
 * 
 */

@Entity
@Table(name = "road_quality")
public class RoadQuality implements Comparable<RoadQuality> {

	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;

	@Column(name = "quality", unique = true, length = 45)
	private String quality;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "roadQuality", cascade = CascadeType.ALL)
	private Set<ConnectionFeature> connectionsFeature = new HashSet<ConnectionFeature>(
			0);

	public RoadQuality() {
		super();
	}

	public RoadQuality(String quality, Set<ConnectionFeature> connectionsFeature) {
		super();
		this.quality = quality;
		this.connectionsFeature = connectionsFeature;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getQuality() {
		return quality;
	}

	public void setQuality(String quality) {
		this.quality = quality;
	}

	public Set<ConnectionFeature> getConnectionsFeature() {
		return connectionsFeature;
	}

	public void setConnectionsFeature(Set<ConnectionFeature> connectionsFeature) {
		this.connectionsFeature = connectionsFeature;
	}

	@Override
	public String toString() {
		return "road_quality_id - " + id + "; quality - " + quality;
	}

	@Override
	public int hashCode() {
		int hash = 43;
		hash = hash * 11 + ((id == null) ? 0 : id.hashCode());
		hash = hash * 11 + ((quality == null) ? 0 : quality.hashCode());
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof RoadQuality))
			return false;
		RoadQuality entry = (RoadQuality) obj;
		return id.equals(entry.getId()) && quality.equals(entry.getQuality());
	}

	@Override
	public int compareTo(RoadQuality compareRoadQuality) {
		return compareRoadQuality.getId() - this.id;
	}

}
